<?php
class CUrlruleModel extends CommonModel{
    protected $tableName="urlrule";
    
    /**
     * 获取自定义URL规则
     * @param string $ruleid 规则id
     * @return string
     */
    function GetUrlRule($ruleid) {
        static $_UrlRule = array();
        if(isset($_UrlRule[$ruleid])){
            return $_UrlRule[$ruleid];//有静态变量直接返回
        }
        $UrlRules=array();
        //先从缓存中取
        if (($UrlRules = F("UrlRule")) && isset($UrlRules[$ruleid])) {
            $_UrlRule[$ruleid]=$UrlRules[$ruleid];
            return $_UrlRule[$ruleid];
        } else {
           
            $re = $this->field(TRUE)->select(); //读取所有url规则
            if ($re) {
                foreach ($re as $v) {
                    $UrlRules[$v['action']] = $v; //以action字段为key重新构建数组
                }
            }
            F("UrlRule", $UrlRules);
            $_UrlRule[$ruleid]=$UrlRules[$ruleid];
            return $_UrlRule[$ruleid];
        }
    }
}
